package net.pzc.log;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleLogger implements ILiteLogger {
	public static int LV_DEBUG = 0;
	public static int LV_INFO = 1;
	public static int LV_WARN = 2;
	public static int LV_ERROR = 3;

	private static int logLevel = LV_DEBUG;

	public static void setLogLevel(int level) {
		logLevel = level;
	}

	private String name = "";

	public SimpleLogger(String name) {
		this.name = name;
	}

	public SimpleLogger(Class<?> clazz) {
		this.name = clazz.getSimpleName();
	}

	public void debug(Object obj) {
		log(LV_DEBUG, obj);
	}

	public void error(Object obj) {
		log(LV_ERROR, obj);
	}

	private void log(int lv, Object obj) {
		SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss,FFF");
		String msg = f.format(new Date()) + " [DEBUG] [" + name + ".java] " + obj;
		if (lv == LV_ERROR) {
			System.err.println(msg);
		} else if (lv >= logLevel) {
			System.out.println(msg);
		}
	}
}
